﻿@model CategoryModel

@if (Model.Id > 0)
{
    <div class="card-body">
        @await Html.PartialAsync("Table", new DataTablesModel
        {
            Name = "products-grid",
            UrlRead = new DataUrl("ProductList", "Category", new RouteValueDictionary { [nameof(Model.CategoryProductSearchModel.CategoryId)] = Model.CategoryProductSearchModel.CategoryId }),
            UrlDelete = new DataUrl("ProductDelete", "Category", null),
            UrlUpdate = new DataUrl("ProductUpdate", "Category", null),
            Length = Model.CategoryProductSearchModel.PageSize,
            LengthMenu = Model.CategoryProductSearchModel.AvailablePageSizes,
            ColumnCollection = new List<ColumnProperty>
                {
                    new ColumnProperty(nameof(CategoryProductModel.ProductName))
                    {
                        Title = T("Admin.Catalog.Categories.Products.Fields.Product").Text
                    },
                    new ColumnProperty(nameof(CategoryProductModel.IsFeaturedProduct))
                    {
                        Title = T("Admin.Catalog.Categories.Products.Fields.IsFeaturedProduct").Text,
                        Width = "150",
                        ClassName = NopColumnClassDefaults.CenterAll,
                        Render = new RenderBoolean(),
                        Editable = true,
                        EditType = EditType.Checkbox
                    },
                    new ColumnProperty(nameof(CategoryProductModel.DisplayOrder))
                    {
                        Title = T("Admin.Catalog.Categories.Products.Fields.DisplayOrder").Text,
                        Width = "150",
                        ClassName = NopColumnClassDefaults.CenterAll,
                        Editable = true,
                        EditType = EditType.Number
                    },
                    new ColumnProperty(nameof(CategoryProductModel.ProductId))
                    {
                        Title = T("Admin.Common.View").Text,
                        Width = "150",
                        ClassName = NopColumnClassDefaults.Button,
                        Render = new RenderButtonView(new DataUrl("~/Admin/Product/Edit/", nameof(CategoryProductModel.ProductId)))
                    },
                    new ColumnProperty(nameof(CategoryProductModel.Id))
                    {
                        Title = T("Admin.Common.Edit").Text,
                        Width = "200",
                        ClassName =  NopColumnClassDefaults.Button,
                        Render = new RenderButtonsInlineEdit()
                    },
                    new ColumnProperty(nameof(CategoryProductModel.Id))
                    {
                        Title = T("Admin.Common.Delete").Text,
                        Width = "100",
                        Render = new RenderButtonRemove(T("Admin.Common.Delete").Text),
                        ClassName = NopColumnClassDefaults.Button
                    }
                }
        })
    </div>
    <div class="card-footer">
        <button type="submit" id="btnAddNewProduct"
                onclick="javascript:OpenWindow('@(Url.Action("ProductAddPopup", "Category", new { categoryId = Model.Id, btnId = "btnRefreshProducts", formId = "category-form" }))', 800, 800, true); return false;"
                class="btn btn-primary">
            @T("Admin.Catalog.Categories.Products.AddNew")
        </button>
        <button type="submit" id="btnRefreshProducts" style="display: none"></button>
        <script>
            $(document).ready(function () {
                $('#btnRefreshProducts').click(function () {
                    //refresh grid
                    updateTable('#products-grid');

                    //return false to don't reload a page
                    return false;
                });
            });
        </script>
    </div>
}
else
{
    <div class="card-body">
        @T("Admin.Catalog.Categories.Products.SaveBeforeEdit")
    </div>
}

